<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%url_task_item}}".
 *
 * @property integer $id
 * @property integer $task_id
 * @property string $url
 * @property string $arg
 * @property string $method
 * @property string $lang
 * @property string $host
 * @property string $user_agent
 * @property integer $type
 * @property integer $status
 * @property integer $visit_cnt
 * @property string $response
 * @property string $msg
 * @property string $create_time
 */
class TaskItem extends \yii\db\ActiveRecord
{

    const TYPE_LIANTONG =   1;
    const TYPE_JS   =   2;
    const TYPE_PE   =   3;
    const TYPE_ELF  =   4;
    const TYPE_NORMAL   =   5;

    const STATUS_START  =   0;
    const STATUS_PROCESSING =   1;
    const STATUS_DONE   =   2;
    const STATUS_ERROR  =   3;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%url_task_item}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['task_id'], 'required'],
            [['task_id', 'type', 'status', 'visit_cnt'], 'integer'],
            [['url', 'arg', 'user_agent', 'response', 'msg'], 'string'],
            [['create_time'], 'safe'],
            [['method'], 'string', 'max' => 10],
            [['lang'], 'string', 'max' => 50],
            [['host'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'task_id' => '任务ID',
            'url' => 'URL',
            'arg' => '参数',
            'method' => '访问类型',
            'lang' => '语言',
            'host' => '域名',
            'user_agent' => 'Agent',
            'type' => '威胁类型',
            'status' => '状态',
            'visit_cnt' => '访问次数',
            'response' => '响应内容',
            'msg' => '错误消息',
            'create_time' => '创建时间',
        ];
    }

    public static function getType($status = null){
        $status_arr= [
            self::TYPE_LIANTONG=>'通联指令威胁',
            self::TYPE_JS=>'js代码威胁',
            self::TYPE_PE=>'PE文件威胁',
            self::TYPE_ELF=>'ELF文件威胁',
            self::TYPE_NORMAL=>'正常',
        ];
        if(!is_null($status)){
            return $status_arr[$status];
        }
        return $status_arr;
    }

    public static function getStatus($status = null){
        $status_arr= [
            self::STATUS_START=>'已提交',
            self::STATUS_PROCESSING=>'正在处理',
            self::STATUS_DONE=>'已处理',
            self::STATUS_ERROR=>'处理失败',
        ];
        if(!is_null($status)){
            return $status_arr[$status];
        }
        return $status_arr;
    }
    public static function getMethod($status = null){
        $status_arr= [
            'GET'=>'GET',
            'POST'=>'POST',
        ];
        if(!is_null($status)){
            return $status_arr[$status];
        }
        return $status_arr;
    }

}
